//===--- KnownObjCMethods.def - Designated Initializers ---------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines the database of known methods for various
// Objective-C classes, along with flags that describe how their
// import into Swift should be altered.
//===----------------------------------------------------------------------===//

// INSTANCE_METHOD(ClassName, Selector, Options)
// CLASS_METHOD(ClassName, Selector, Options)
// 
//   Describes an instance or class method.
//
//   ClassName: The name of the class.
//
//   Selector: A parenthesized sequence containing the # of selector
//   pieces followed by strings containing the selector pieces.
//
//   Options: A set of OR'd options describing what specific behavior
//   should be applied to this method. The possibilities are:
//     DesignatedInit: Mark this as a designated initializer of its class.
//     FactoryAsClassMethod: Don't import this factory method as an initializer.
//     Unavailable(Msg): Mark this method as being unavailable, with the given
//       message.
//     OptionalTypeAdjustment: Specifies the optionality of types in the API.
//       Takes variadic arguments. The first argument specifies the # of types
//       followed by the values from OptionalTypeKind enum specifying the
//       optionality of each type. We assume that the first encoded type is the
//       method's return type. Pass '0' as the first argument for a method with
//       only non-optional (OTK_None) types.
//
// OBJC_CLASS(ClassName, Options)
//
//   Describes default method options in a class. This can be used
//   to list options common to all/most methods of the audited class. These
//   defaults can be overwritten by using INSTANCE_METHOD and CLASS_METHOD.
//
// OBJC_PROTOCOL(ClassName, Options)
//
//   Describes default method options in a class. This can be used
//   to list options common to all/most methods of the audited class. These
//   defaults can be overwritten by using INSTANCE_METHOD and CLASS_METHOD.
//
// OBJC_PROPERTY(ContextName, PropertyName, OptionalTypeKind)
//
//   Describes the optionality if the type of the Objective C property.
//

#ifndef INSTANCE_METHOD
#  error define INSTANCE_METHOD before including KnownMethods.def
#endif

#ifndef PROTOCOL_INSTANCE_METHOD
#  error define PROTOCOL_INSTANCE_METHOD before including KnownMethods.def
#endif

#ifndef CLASS_METHOD
#  error define CLASS_METHOD before including KnownMethods.def
#endif

#ifndef OBJC_CLASS
#  error define OBJC_CLASS before including KnownMethods.def
#endif

#ifndef OBJC_PROTOCOL
#  error define OBJC_PROTOCOL before including KnownMethods.def
#endif

#ifndef START_MODULE
#  define START_MODULE(Name)
#endif

START_MODULE(ObjectiveC)
INSTANCE_METHOD(NSObject, (0, "dealloc"), 
                Unavailable("use 'deinit' to define a de-initializer"))

INSTANCE_METHOD(NSObject, (0, "init"), DesignatedInit)
CLASS_METHOD(NSObject, (0, "class"), Unavailable("use 'self' instead"))

// NSObject protocol
PROTOCOL_INSTANCE_METHOD(NSObject, (0, "class"),
                         Unavailable("use 'dynamicType' instead"))

START_MODULE(Foundation)
INSTANCE_METHOD(NSArray, (0, "init"), DesignatedInit)
INSTANCE_METHOD(NSArray, (1, "initWithObjects"), DesignatedInit)
INSTANCE_METHOD(NSArray, (2, "initWithObjects", "count"), DesignatedInit)

INSTANCE_METHOD(NSCountedSet, (1, "initWithCapacity"), DesignatedInit)

INSTANCE_METHOD(NSDate, (0, "init"), DesignatedInit)
INSTANCE_METHOD(NSDate, (1, "initWithTimeIntervalSinceReferenceDate"),
                DesignatedInit)

INSTANCE_METHOD(NSDecimalNumber, (1, "initWithDecimal"), DesignatedInit)

INSTANCE_METHOD(NSDictionary, (0, "init"), DesignatedInit)
INSTANCE_METHOD(NSDictionary, (3, "initWithObjects", "forKeys", "count"),
                DesignatedInit)

CLASS_METHOD(NSDistributedNotificationCenter, (1, "notificationCenterForType"),
             FactoryAsClassMethod)

INSTANCE_METHOD(NSError, (3, "initWithDomain", "code", "userInfo"), 
                DesignatedInit)

INSTANCE_METHOD(NSException, (3, "initWithName", "reason", "userInfo"),
                DesignatedInit)

INSTANCE_METHOD(NSExpression, (1, "initWithExpressionType"), DesignatedInit)

INSTANCE_METHOD(NSExtensionContext, (2, "openURL", "completion"),
                Unavailable("call openURL:completionHandler:"))

INSTANCE_METHOD(NSFileWrapper, (3, "initWithURL", "options", "error"), 
                DesignatedInit)
INSTANCE_METHOD(NSFileWrapper, (1, "initDirectoryWithFileWrappers"),
                DesignatedInit)
INSTANCE_METHOD(NSFileWrapper, (1, "initRegularFileWithContents"), 
                DesignatedInit)
INSTANCE_METHOD(NSFileWrapper, (1, "initSymbolicLinkWithDestinationURL"),
                DesignatedInit)
INSTANCE_METHOD(NSFileWrapper, (1, "initWithSerializedRepresentation"), 
                DesignatedInit)

INSTANCE_METHOD(NSIndexPath, (0, "init"), DesignatedInit)
INSTANCE_METHOD(NSIndexPath, (2, "initWithIndexes", "length"), DesignatedInit)

INSTANCE_METHOD(NSIndexSet, (0, "init"), DesignatedInit)
INSTANCE_METHOD(NSIndexSet, (1, "initWithIndexesInRange"), DesignatedInit)
INSTANCE_METHOD(NSIndexSet, (1, "initWithIndexSet"), DesignatedInit)

OBJC_CLASS(NSInvocation, Unavailable(""))

INSTANCE_METHOD(NSInvocationOperation, (1, "initWithInvocation"), 
                DesignatedInit)

INSTANCE_METHOD(NSMachPort, (1, "initWithMachPort"), DesignatedInit)

INSTANCE_METHOD(NSMutableArray, (0, "init"), DesignatedInit)
INSTANCE_METHOD(NSMutableArray, (1, "initWithCapacity"), DesignatedInit)

INSTANCE_METHOD(NSMutableDictionary, (0, "init"), DesignatedInit)
INSTANCE_METHOD(NSMutableDictionary, (1, "initWithCapacity"), DesignatedInit)

INSTANCE_METHOD(NSMutableOrderedSet, (0, "init"), DesignatedInit)
INSTANCE_METHOD(NSMutableOrderedSet, (1, "initWithCapacity"), DesignatedInit)

INSTANCE_METHOD(NSMutableSet, (0, "init"), DesignatedInit)
INSTANCE_METHOD(NSMutableSet, (1, "initWithCapacity"), DesignatedInit)

INSTANCE_METHOD(NSNetService, (4, "initWithDomain", "type", "name", "port"),
                DesignatedInit)

INSTANCE_METHOD(NSNotificationQueue, (1, "initWithNotificationCenter"),
                DesignatedInit)

INSTANCE_METHOD(NSOrderedSet, (0, "init"), DesignatedInit)
INSTANCE_METHOD(NSOrderedSet, (2, "initWithObjects", "count"), DesignatedInit)

INSTANCE_METHOD(NSPortMessage, 
                (3, "initWithSendPort", "receivePort", "components"),
                DesignatedInit)

CLASS_METHOD(NSProcessInfo, (0, "processInfo"), FactoryAsClassMethod)

INSTANCE_METHOD(NSScriptObjectSpecifier, 
                (3, "initWithContainerClassDescription", "containerSpecifier",
                 "key"), DesignatedInit)

INSTANCE_METHOD(NSSet, (0, "init"), DesignatedInit)
INSTANCE_METHOD(NSSet, (2, "initWithObjects", "count"), DesignatedInit)

INSTANCE_METHOD(NSThread, (0, "init"), DesignatedInit)

INSTANCE_METHOD(NSURL, (2, "initWithString", "relativeToURL"), DesignatedInit)

INSTANCE_METHOD(NSURLProtocol, 
                (3, "initWithRequest", "cachedResponse", "client"), 
                DesignatedInit)

INSTANCE_METHOD(NSURLRequest, 
                (3, "initWithURL", "cachePolicy", "timeoutInterval"),
                DesignatedInit)

INSTANCE_METHOD(NSURLResponse, 
                (4, "initWithURL", "MIMEType", "expectedContentLength", 
                 "textEncodingName"), DesignatedInit)

INSTANCE_METHOD(NSValue, (2, "initWithBytes", "objCType"), DesignatedInit)

INSTANCE_METHOD(NSXMLDocument, (3, "initWithData", "options", "error"),
                DesignatedInit)

INSTANCE_METHOD(NSXMLDTD, (3, "initWithData", "options", "error"),
                DesignatedInit)

INSTANCE_METHOD(NSXMLParser, (1, "initWithData"), DesignatedInit)

START_MODULE(AppKit)
INSTANCE_METHOD(NSCell, (0, "init"), DesignatedInit)
INSTANCE_METHOD(NSCell, (1, "initWithCoder"), DesignatedInit)
INSTANCE_METHOD(NSCell, (1, "initTextCell"), DesignatedInit)
INSTANCE_METHOD(NSCell, (1, "initImageCell"), DesignatedInit)

INSTANCE_METHOD(NSControl, (1, "initWithFrame"), DesignatedInit)

INSTANCE_METHOD(NSCursor, (2, "initWithImage", "hotSpot"), DesignatedInit)

INSTANCE_METHOD(NSDocument, (0, "init"), DesignatedInit)

INSTANCE_METHOD(NSDocumentController, (0, "init"), DesignatedInit)

INSTANCE_METHOD(NSDraggingImageComponent, (1, "initWithKey"), DesignatedInit)

INSTANCE_METHOD(NSDraggingItem, (1, "initWithPasteboardWriter"), DesignatedInit)

INSTANCE_METHOD(NSFontManager, (0, "init"), DesignatedInit)

INSTANCE_METHOD(NSFormCell, (1, "initTextCell"), DesignatedInit)

INSTANCE_METHOD(NSGradient, (3, "initWithColors", "atLocations", "colorSpace"),
                DesignatedInit)

INSTANCE_METHOD(NSImageCell, (0, "init"), DesignatedInit)
INSTANCE_METHOD(NSImageCell, (1, "initWithCoder"), DesignatedInit)
INSTANCE_METHOD(NSImageCell, (1, "initTextCell"), DesignatedInit)
INSTANCE_METHOD(NSImageCell, (1, "initImageCell"), DesignatedInit)

INSTANCE_METHOD(NSLayoutManager, (0, "init"), DesignatedInit)

INSTANCE_METHOD(NSMatrix, 
                (5, "initWithFrame", "mode", "cellClass", "numberOfRows", 
                    "numberOfColumns"), DesignatedInit)
INSTANCE_METHOD(NSMatrix, 
                (5, "initWithFrame", "prototype", "cellClass", "numberOfRows", 
                    "numberOfColumns"), DesignatedInit)

INSTANCE_METHOD(NSMenu, (1, "initWithTitle"), DesignatedInit)

INSTANCE_METHOD(NSMenuView, (1, "initWithFrame"), DesignatedInit)

INSTANCE_METHOD(NSPopUpButtonCell, (2, "initTextCell", "pullsDown"),
                DesignatedInit)

INSTANCE_METHOD(NSPrintInfo, (1, "initWithDictionary"), DesignatedInit)

INSTANCE_METHOD(NSRulerMarker, 
                (4, "initWithRulerView", "markerLocation", "image", 
                 "imageOrigin"), DesignatedInit)

INSTANCE_METHOD(NSRulerView, (2, "initWithScrollView", "orientation"),
                DesignatedInit)

INSTANCE_METHOD(NSTableColumn, (1, "initWithIdentifier"), DesignatedInit)

// FIXME: Differs from UIKit
// INSTANCE_METHOD(NSTextAttachment, (1, "initWithFileWrapper"), DesignatedInit)

INSTANCE_METHOD(NSTextBlock, (0, "init"), DesignatedInit)

// FIXME: Differs from UIKit
// INSTANCE_METHOD(NSTextContainer, (1, "initWithContainerSize"), 
//                 DesignatedInit)

INSTANCE_METHOD(NSTextFieldCell, (1, "initWithCoder"), DesignatedInit)
INSTANCE_METHOD(NSTextFieldCell, (1, "initTextCell"), DesignatedInit)
INSTANCE_METHOD(NSTextFieldCell, (1, "initImageCell"), DesignatedInit)

INSTANCE_METHOD(NSTextFinder, (0, "init"), DesignatedInit)

INSTANCE_METHOD(NSTextInputContext, (1, "initWithClient"), DesignatedInit)

INSTANCE_METHOD(NSTextTableBlock, 
                (5, "initWithTable", "startingRow", "rowSpan", 
                 "startingColumn", "columnSpan"), DesignatedInit)

INSTANCE_METHOD(NSTextView, (2, "initWithFrame", "textContainer"), 
                DesignatedInit)
INSTANCE_METHOD(NSTextView, (1, "initWithFrame"), DesignatedInit)

INSTANCE_METHOD(NSUserDefaultsController, 
                (2, "initWithDefaults", "initialValues"), DesignatedInit)


INSTANCE_METHOD(NSWindow, 
                (4, "initWithContentRect", "styleMask", "backing", "defer"), 
                DesignatedInit)

INSTANCE_METHOD(NSWindowController, (1, "initWithWindow"), DesignatedInit)

// Optional type annotations for NSView.
// Consider all parameter types in NSView methods to be non-optional and
// the return optional.
OBJC_CLASS(NSView, OptionalTypeAdjustment(1, OTK_Optional))
INSTANCE_METHOD(NSView, (1, "setSubviews"),
                OptionalTypeAdjustment(2, OTK_None, OTK_None))
INSTANCE_METHOD(NSView, (1, "addSubview"), OptionalTypeAdjustment(0))
INSTANCE_METHOD(NSView, (3, "addSubview", "positioned", "relativeTo"),
                OptionalTypeAdjustment(4, OTK_None, OTK_None, OTK_None,
                                          OTK_Optional));
INSTANCE_METHOD(NSView,
                (1, "viewWillMoveToSuperview"),
                OptionalTypeAdjustment(2, OTK_None, OTK_Optional))
INSTANCE_METHOD(NSView,
                (1, "viewWillMoveToWindow"),
                OptionalTypeAdjustment(2, OTK_None, OTK_Optional))
INSTANCE_METHOD(NSView, (2, "convertPoint", "fromView"),
                OptionalTypeAdjustment(3, OTK_None, OTK_None, OTK_Optional))
INSTANCE_METHOD(NSView, (2, "convertPoint", "toView"),
                OptionalTypeAdjustment(3, OTK_None, OTK_None, OTK_Optional))
INSTANCE_METHOD(NSView, (2, "convertSize", "fromView"),
                OptionalTypeAdjustment(3, OTK_None, OTK_None, OTK_Optional))
INSTANCE_METHOD(NSView, (2, "convertSize", "toView"),
                OptionalTypeAdjustment(3, OTK_None, OTK_None, OTK_Optional))
INSTANCE_METHOD(NSView, (2, "convertRect", "fromView"),
                OptionalTypeAdjustment(3, OTK_None, OTK_None, OTK_Optional))
INSTANCE_METHOD(NSView, (2, "convertRect", "toView"),
                OptionalTypeAdjustment(3, OTK_None, OTK_None, OTK_Optional))
INSTANCE_METHOD(NSView, (3, "beginDraggingSessionWithItems", "event", "source"),
                OptionalTypeAdjustment(3, OTK_ImplicitlyUnwrappedOptional,
                                          OTK_ImplicitlyUnwrappedOptional,
                                          OTK_ImplicitlyUnwrappedOptional))
INSTANCE_METHOD(NSView,
                (7, "dragImage", "at", "offset", "event", "pasteboard",
                    "source", "slideBack"),
                OptionalTypeAdjustment(6, OTK_ImplicitlyUnwrappedOptional,
                                          OTK_None,
                                          OTK_ImplicitlyUnwrappedOptional,
                                          OTK_ImplicitlyUnwrappedOptional,
                                          OTK_ImplicitlyUnwrappedOptional,
                                          OTK_ImplicitlyUnwrappedOptional))
INSTANCE_METHOD(NSView, (4, "dragFile", "fromRect", "slideBack", "event"),
                OptionalTypeAdjustment(5, OTK_ImplicitlyUnwrappedOptional,
                                          OTK_None,
                                          OTK_ImplicitlyUnwrappedOptional,
                                          OTK_ImplicitlyUnwrappedOptional,
                                          OTK_ImplicitlyUnwrappedOptional))
INSTANCE_METHOD(NSView,
                (5, "dragPromisedFilesOfTypes", "fromRect", "source",
                    "slideBack", "event"),
                OptionalTypeAdjustment(6, OTK_ImplicitlyUnwrappedOptional,
                                          OTK_None,
                                          OTK_ImplicitlyUnwrappedOptional,
                                          OTK_ImplicitlyUnwrappedOptional,
                                          OTK_ImplicitlyUnwrappedOptional,
                                          OTK_ImplicitlyUnwrappedOptional))
INSTANCE_METHOD(NSView, (2, "enterFullScreenMode", "withOptions"),
                OptionalTypeAdjustment(3, OTK_ImplicitlyUnwrappedOptional,
                                          OTK_Optional, OTK_Optional))
INSTANCE_METHOD(NSView, (1, "exitFullScreenModeWithOptions"),
                OptionalTypeAdjustment(2, OTK_ImplicitlyUnwrappedOptional,
                                          OTK_Optional))
INSTANCE_METHOD(NSView, (2, "showDefinitionForAttributedString", "atPoint"),
                OptionalTypeAdjustment(2, OTK_ImplicitlyUnwrappedOptional,
                                          OTK_Optional))
INSTANCE_METHOD(NSView,
                (4, "showDefinitionForAttributedString", "range", "options",
                    "baselineOriginProvider"),
                OptionalTypeAdjustment(4, OTK_ImplicitlyUnwrappedOptional,
                                          OTK_Optional,
                                          OTK_ImplicitlyUnwrappedOptional,
                                          OTK_Optional))
INSTANCE_METHOD(NSView,
                (1, "constraintsAffectingLayoutForOrientation"),
                OptionalTypeAdjustment(1, OTK_None))

OBJC_PROPERTY(NSView, window, OTK_Optional)
OBJC_PROPERTY(NSView, superview, OTK_Optional)
OBJC_PROPERTY(NSView, subviews, OTK_None)
OBJC_PROPERTY(NSView, opaqueAncestor, OTK_Optional)
OBJC_PROPERTY(NSView, makeBackingLayer, OTK_None)
OBJC_PROPERTY(NSView, trackingAreas, OTK_None)
OBJC_PROPERTY(NSView, enclosingScrollView, OTK_Optional)
OBJC_PROPERTY(NSView, toolTip, OTK_Optional)
OBJC_PROPERTY(NSView, nextKeyView, OTK_Optional)
OBJC_PROPERTY(NSView, previousKeyView, OTK_Optional)
OBJC_PROPERTY(NSView, nextValidKeyView, OTK_Optional)
OBJC_PROPERTY(NSView, previousValidKeyView, OTK_Optional)
OBJC_PROPERTY(NSView, printJobTitle, OTK_None)
OBJC_PROPERTY(NSView, registeredDraggedTypes, OTK_Optional)

START_MODULE(NotificationCenter)
CLASS_METHOD(NCWidgetController, (0, "widgetController"), FactoryAsClassMethod)

START_MODULE(UIKit)

// FIXME: Differs from AppKit
// INSTANCE_METHOD(NSTextAttachment, (2, "initWithData", "ofType"), 
//                 DesignatedInit)

INSTANCE_METHOD(NSTextContainer, (1, "initWithSize"), DesignatedInit)

INSTANCE_METHOD(UIAttachmentBehavior, 
                (4, "initWithItem", "offsetFromCenter", "attachedToItem", 
                 "offsetFromCenter"), DesignatedInit)

INSTANCE_METHOD(UICollectionView, (2, "initWithFrame", "collectionViewLayout"),
                DesignatedInit)

INSTANCE_METHOD(UIDocument, (1, "initWithFileURL"), DesignatedInit)

INSTANCE_METHOD(UIGestureRecognizer, (2, "initWithTarget", "action"), 
                DesignatedInit)

INSTANCE_METHOD(UIInputView, (2, "initWithFrame", "inputViewStyle"),
                DesignatedInit)

INSTANCE_METHOD(UINavigationItem, (1, "initWithTitle"), DesignatedInit)

INSTANCE_METHOD(UIStoryboardSegue, 
                (3, "initWithIdentifier", "source", "destination"), 
                DesignatedInit)

INSTANCE_METHOD(UITableViewCell, (2, "initWithStyle", "reuseIdentifier"), 
                DesignatedInit)

INSTANCE_METHOD(UITextView, (2, "initWithFrame", "textContainer"),
                DesignatedInit)

INSTANCE_METHOD(UIView, (1, "initWithFrame"), DesignatedInit)

INSTANCE_METHOD(UIViewController, (2, "initWithNibName", "bundle"), 
                DesignatedInit)

// Consider all types in UIFont methods to be non-optional.
OBJC_CLASS(UIFont, OptionalTypeAdjustment(0))
CLASS_METHOD(UIFont, (2, "fontWithName", "size"),
             OptionalTypeAdjustment(1, OTK_ImplicitlyUnwrappedOptional));
OBJC_PROPERTY(UIFont, familyName, OTK_None)
OBJC_PROPERTY(UIFont, fontName, OTK_None)


// Consider all parameter types in NSView methods to be non-optional and the
// return optional.
OBJC_PROTOCOL(UIApplicationDelegate, OptionalTypeAdjustment(1, OTK_None))
PROTOCOL_INSTANCE_METHOD(UIApplicationDelegate,
                (2, "application", "willFinishLaunchingWithOptions"),
                OptionalTypeAdjustment(3, OTK_None, OTK_None,
                                          OTK_ImplicitlyUnwrappedOptional));
PROTOCOL_INSTANCE_METHOD(UIApplicationDelegate,
                (2, "application", "didFinishLaunchingWithOptions"),
                OptionalTypeAdjustment(3, OTK_None, OTK_None,
                                          OTK_ImplicitlyUnwrappedOptional));
PROTOCOL_INSTANCE_METHOD(UIApplicationDelegate,
                (4,"application", "openURL", "sourceApplication", "annotation"),
                OptionalTypeAdjustment(4, OTK_None, OTK_None, OTK_None,
                                       OTK_ImplicitlyUnwrappedOptional));
PROTOCOL_INSTANCE_METHOD(UIApplicationDelegate,
                (4, "application", "handleActionWithIdentifier",
                    "forLocalNotification", "completionHandler"),
                OptionalTypeAdjustment(3, OTK_None, OTK_None, OTK_Optional));
PROTOCOL_INSTANCE_METHOD(UIApplicationDelegate,
                (4, "application", "handleActionWithIdentifier",
                    "forRemoteNotification", "completionHandler"),
                OptionalTypeAdjustment(3, OTK_None, OTK_None, OTK_Optional));
PROTOCOL_INSTANCE_METHOD(UIApplicationDelegate,
                (3, "application",
                    "viewControllerWithRestorationIdentifierPath",
                    "coder"),
                OptionalTypeAdjustment(4, OTK_Optional,
                                          OTK_None, OTK_None, OTK_None));
OBJC_PROTOCOL_PROPERTY(UIApplicationDelegate, window, OTK_Optional)

#undef INSTANCE_METHOD
#undef PROTOCOL_INSTANCE_METHOD
#undef CLASS_METHOD
#undef OBJC_PROPERTY
#undef OBJC_PROTOCOL_PROPERTY
#undef OBJC_CLASS
#undef OBJC_PROTOCOL
#undef START_MODULE
